home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / SidebarPanel.js < prev    next >
Encoding:
Text File  |  2002-10-25  |  63.7 KB  |  1,819 lines

  1. var processInviteTimer = -1;
  2. var initialState = "Offline";
  3.  
  4. /*
  5.  * Function: UpdateMenuItemsForApp(isonline)
  6.  * Arguments: 
  7.  *       isonline -- login state (offline/online)
  8.  * Return: None
  9.  * Description: This function is called when the user signs on/off and on load of Standalone.
  10.  * According to the the input parameter, the menu items in the standalone get updated.
  11. */
  12.  
  13. function UpdateMenuItemsForApp(isonline)
  14. {
  15.   if ( isonline == "Offline"){
  16.    ClearProcessTimer();
  17.    top.title = aimString("app.title.SignOn");
  18.    top.document.getElementById("miSignOn").setAttribute("label", aimString("miSignOn.SignOn"));
  19.    top.document.getElementById("miSignOn").setAttribute("oncommand", "cmdSignOn();");
  20.    top.document.getElementById("miSignOn").setAttribute("disabled", "false");
  21.    top.document.getElementById("miSignOffClose").setAttribute("disabled", "true");
  22.    top.document.getElementById("miIcqSignOn").setAttribute("label", aimString("miSignOn.SignOn"));
  23.    top.document.getElementById("miIcqSignOn").setAttribute("oncommand", "cmdSignOn();");
  24.    top.document.getElementById("miIcqSignOn").setAttribute("disabled", "false");
  25.    top.document.getElementById("miIcqSignOffClose").setAttribute("disabled", "true");
  26.    top.document.getElementById("change_password").setAttribute("disabled", "true");
  27.    top.document.getElementById("confirm_account").setAttribute("disabled", "true");
  28.    top.document.getElementById("change_email").setAttribute("disabled", "true");
  29.    top.document.getElementById("people_menu").setAttribute("hidden", "true");
  30.    top.document.getElementById("people_menu_icq").setAttribute("hidden", "true");
  31.    top.document.getElementById("menu_PeoplePopup").setAttribute("collapsed", "true");
  32.    top.document.getElementById("menu_PeoplePopup_icq").setAttribute("collapsed", "true");
  33.    top.document.getElementById("menu_Away").setAttribute("hidden", "true");
  34.    top.document.getElementById("away_seperator").setAttribute("hidden", "true");
  35.    top.document.getElementById("menu_Away_icq").setAttribute("hidden", "true");
  36.    top.document.getElementById("away_icq_seperator").setAttribute("hidden", "true");
  37.    top.document.getElementById("cmd_IM").setAttribute("disabled", "true");
  38.    top.document.getElementById("cmd_import").setAttribute("disabled", "true");
  39.    top.document.getElementById("cmd_export").setAttribute("disabled", "true");
  40.   }
  41.  else {
  42.    top.document.getElementById("miSignOn").setAttribute("label", aimString("miSignOn.SignOff"));
  43.    top.document.getElementById("miSignOn").setAttribute("oncommand", "cmdSignOff();");
  44.    top.document.getElementById("miSignOn").setAttribute("disabled", "true");
  45.    top.document.getElementById("miSignOffClose").setAttribute("disabled", "false");
  46.    top.document.getElementById("miIcqSignOn").setAttribute("label", aimString("miSignOn.SignOff"));
  47.    top.document.getElementById("miIcqSignOn").setAttribute("oncommand", "cmdSignOff();");
  48.    top.document.getElementById("miIcqSignOn").setAttribute("disabled", "true");
  49.    top.document.getElementById("miIcqSignOffClose").setAttribute("disabled", "false");
  50.    top.document.getElementById("change_password").setAttribute("disabled", "false");
  51.    top.document.getElementById("confirm_account").setAttribute("disabled", "false");
  52.    top.document.getElementById("change_email").setAttribute("disabled", "false");
  53.    if (isIcq() == true) {
  54.      top.document.getElementById("people_menu_icq").setAttribute("hidden", "false");
  55.      top.document.getElementById("menu_PeoplePopup_icq").setAttribute("collapsed", "false");
  56.      top.document.getElementById("menu_Away_icq").setAttribute("hidden", "false");
  57.      top.document.getElementById("away_icq_seperator").setAttribute("hidden", "false");
  58.      top.document.getElementById("people_menu").setAttribute("hidden", "true");
  59.      top.document.getElementById("menu_PeoplePopup").setAttribute("collapsed", "true");
  60.      top.document.getElementById("menu_Away").setAttribute("hidden", "true");
  61.      top.document.getElementById("away_seperator").setAttribute("hidden", "true");
  62.      }
  63.      else
  64.      {
  65.      top.document.getElementById("people_menu").setAttribute("hidden", "false");
  66.      // top.document.getElementById("menu_Away").setAttribute("hidden", "false");
  67.      top.document.getElementById("menu_PeoplePopup").setAttribute("collapsed", "false");
  68.      top.document.getElementById("menu_Away").setAttribute("hidden", "false");
  69.      top.document.getElementById("away_seperator").setAttribute("hidden", "false");
  70.      top.document.getElementById("people_menu_icq").setAttribute("hidden", "true");
  71.      top.document.getElementById("menu_PeoplePopup_icq").setAttribute("collapsed", "true");
  72.      top.document.getElementById("menu_Away_icq").setAttribute("hidden", "true");
  73.      top.document.getElementById("away_icq_seperator").setAttribute("hidden", "true");
  74.      }
  75.    top.document.getElementById("cmd_IM").setAttribute("disabled", "false");
  76.    top.document.getElementById("cmd_import").setAttribute("disabled", "false");
  77.    top.document.getElementById("cmd_export").setAttribute("disabled", "false");
  78.    // SetupCommandUpdateHandlers() will initialize command observers for Online tree and listsetup tree.
  79.    // timeout is used coz it takes a bit of time for the Online and listsetup tab to show up!
  80.    setTimeout("AimSetupCommandUpdateHandlers()", 500);
  81.    aimMigrateBuddyList( aimSessionCurrentScreenName() );
  82.    SetAwayMenu();
  83.    SetProcessTimer(10000);
  84.  
  85.  
  86.  }
  87. }
  88.  
  89. /****************  Window Management *****************/
  90.  
  91. function AimSidebarPanelOnWndLoad() {
  92.   //register buddy list observer for sidebar.
  93.   addSidebarBuddyListObserver();
  94.   var todayhide = aimPrefsManager().GetBoolPref("aim.internal.hidetoday", null, false);
  95.   if (todayhide)
  96.   {
  97.     document.getElementById("btnbuddyorgtoday").setAttribute("style", "display: none" );
  98.   }
  99.   var hasState;
  100.   var hideConnection = aimPrefsManager().GetBoolPref("aim.session.hideconnection", null, false);
  101.   if (hideConnection == true) {
  102.     picker = document.getElementById('sessionPicker');
  103.     picker.setAttribute("style", "display: none" );
  104.     picker = document.getElementById('sessionPickerLabel');
  105.     picker.setAttribute("style", "display: none" );
  106.   } 
  107.  
  108.   enableSignOnButton(false);
  109.     // Read signon prefs. We need to load at least the screen name here,
  110.     // but might as well load the password and autoLogin prefs, too.
  111.  
  112.     var screenName = aimPrefsManager().GetCharPref("aim.session.screenname", null, true);
  113.     
  114.     //dump("ScreenName is " + screenName);
  115.  
  116.     var password = aimSessionGetPassword(null);
  117.     var autoLogin = aimPrefsManager().GetBoolPref("aim.session.autologin", null, false);
  118.     var firstTime = aimPrefsManager().GetBoolPref("aim.session.firsttime", null, true); // firsttime is a GLOBAL pref
  119.     var alreadyFinishedWizard = aimPrefsManager().GetBoolPref("aim.session.finishedwizard", null, false);
  120.  
  121.   addSidebarSessionListener();  
  122.   var connectionName = aimPrefsManager().GetCharPref("aim.session.userconnectionname", null, true);
  123.   setMenuPopUp (connectionName);
  124.     top.AIMDocumentPath=window;
  125.  
  126.   // If this is the first time the user is launching aim, pop open the wizard.
  127.   // If not, ignore and move on.
  128.   if (firstTime) {
  129.     //***** turning off this behavior but we may still need to know if the
  130.     //***** wizard has run yet or not.
  131.     //aimGlobalCmdStartupWizard();
  132.     // Set pref so we don't pop open the wizard again automatically if the user doesn't finish the wizard the first time.
  133.     aimPrefsManager().SetBoolPref("aim.session.firsttime",false, null, true);
  134.   }    
  135.  
  136.     // Initialize online state
  137.  
  138.     var state = aimRDFDataSource().GetTarget(aimRDFSession(), aimRDFSessionState(), true);
  139.     
  140.     if (state == null){
  141.         state = aimRDF().GetLiteral("Register");    
  142.     hasState = true;    
  143.         }
  144.  
  145.   if (alreadyFinishedWizard && (hasState || state == aimRDF().GetLiteral("Register")))
  146.     state = aimRDF().GetLiteral("Offline");
  147.  
  148.    if (screenName && screenName !="" && !alreadyFinishedWizard){
  149.       //we are in that special state of having had another wizard set a screen name
  150.       //but we havent finished up the 'registration'
  151.       aimSessionRegister(screenName);
  152.       aimPrefsManager().SetBoolPref("aim.session.finishedwizard",true, null, true);
  153.       //preset the latestaimscreenname so it will be preserved  if the user
  154.       //switches services before ever signing on it will still remember the
  155.       //aim screenname
  156.       aimPrefsManager().SetCharPref("aim.session.latestaimscreenname",screenName, null, true);
  157.       state = aimRDF().GetLiteral("Offline");   
  158.    }  
  159.   // Check whether the Sidebar buddylist is getting loaded or the Standalone one
  160.   CheckIfApp("Aim:AimApp");
  161.   CheckIfSidebar();
  162.  
  163.   // If App then initialize the menu items.
  164.   if ((IsApp) && (!IsSidebar)) 
  165.     UpdateMenuItemsForApp("Offline");
  166.   
  167.     
  168.   OnlineObserver.onAssert(aimRDFDataSource(), aimRDFSession(), aimRDFSessionState(), state);
  169.   // Watch future changes to online state
  170.     aimRDFDataSource().AddObserver(OnlineObserver);
  171.     
  172.     
  173.   var firstLogin = aimPrefsManager().GetBoolPref("aim.session.appfirstlogin", null,true);
  174.   // Auto login
  175.     
  176. if (screenName && screenName != '' && password && password != '' && autoLogin && firstLogin != false &&
  177.     connectionName && connectionName !='') {
  178.       if (state.EqualsNode(aimRDF().GetLiteral("Offline"))) {
  179.  
  180.             if (!IsServiceCorrect(screenName, connectionName)) {
  181.                 return;  
  182.             }
  183.  
  184.             setConnectionInfo (connectionName, "im", screenName);
  185.             aimSessionLogin(screenName, password);
  186.        }
  187.     }
  188.     else
  189.     {
  190.         if (screenName && screenName != '')
  191.         {
  192.             if (!password || password == '')
  193.                 document.getElementById('fldPassword').focus();
  194.       else
  195.         enableSignOnButton(true); //ok..we have SN and password. Enable the signon button
  196.         }
  197.         else
  198.             document.getElementById('fldScreenName').focus();
  199.             
  200.     }
  201. }
  202.  
  203. function resetPopUp()
  204. {
  205.   setMenuPopUp (document.getElementById("sessionTypeListmenu").value);
  206. }
  207.  
  208.  
  209. function AimSidebarPanelSetAwayMsgBtn(){
  210.   var menu = window.document.getElementById("btnaway");
  211.   if (isIcq() == true)
  212.   {
  213.     // this is an Icq session
  214.     var sidebar_file = GetRdfFileUrl("default-messages-icq.rdf", "icqdm.rdf"); 
  215.     menu.setAttribute('ref', "NC:ICQ/AwayMessageBag");  
  216.   }
  217.     else
  218.   {
  219.     var sidebar_file = GetRdfFileUrl("default-messages.rdf", "dm.rdf");
  220.     menu.setAttribute('ref', "NC:AIM/AwayMessageBag");  
  221.   }
  222.   var datasource = aimRDF().GetDataSource(sidebar_file);
  223.   var menudb=menu.database.GetDataSources();
  224.   while   (menudb.hasMoreElements()) {
  225.                 var curDS= menudb.getNext();
  226.               curDS=curDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
  227.                 menu.database.RemoveDataSource(curDS);
  228.         }
  229.     menu.database.AddDataSource(datasource);
  230.   menu.builder.rebuild();
  231. }
  232.  
  233.  
  234. function SetAwayMenu(){
  235.   var menu;
  236.   if (isIcq() == true) {
  237.     menu = top.document.getElementById("menu_Away_icq");
  238.     // this is an Icq session
  239.     var sidebar_file = GetRdfFileUrl("default-messages-icq.rdf", "icqdm.rdf"); 
  240.     menu.setAttribute('ref', "NC:ICQ/AwayMessageBag");  
  241.   }
  242.     else {
  243.     menu = top.document.getElementById("menu_Away");
  244.       var sidebar_file = GetRdfFileUrl("default-messages.rdf", "dm.rdf");  
  245.   }
  246.   var datasource = aimRDF().GetDataSource(sidebar_file);
  247.     var menudb=menu.database.GetDataSources();
  248.   while   (menudb.hasMoreElements()) {
  249.                 var curDS= menudb.getNext();
  250.                 curDS=curDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
  251.                 menu.database.RemoveDataSource(curDS);
  252.         }
  253.     menu.database.AddDataSource(datasource);
  254.     menu.builder.rebuild();
  255. }
  256.  
  257. function AimSidebarPanelOnWndUnload() {
  258.  
  259.     // Save signon fields if offline. If online, we saved during signon.
  260.     var state = aimRDFDataSource().GetTarget(aimRDFSession(), aimRDFSessionState(), true);
  261.     if (state == null || state.EqualsNode(aimRDF().GetLiteral("Offline")))
  262.         SaveFieldsToPrefs();
  263.   aimRDFDataSource().RemoveObserver(OnlineObserver);
  264.   ClearProcessTimer();
  265.   removeSidebarSessionListener();
  266.   removeSidebarBuddyListObserver();
  267. }
  268.  
  269. function InitFieldsFromPrefs( doSNAndPasswd, curScreenName) {
  270.  
  271.  
  272.     if (doSNAndPasswd == true) {
  273.         var screenName = aimPrefsManager().GetCharPref("aim.session.screenname", null, true);
  274.         var password = aimSessionGetPassword(null);
  275.         document.getElementById('fldScreenName').value = screenName;
  276.     }
  277.     var savePassword = aimPrefsManager().GetBoolPref("aim.session.storepassword", null, false);
  278.     var autoLogin = aimPrefsManager().GetBoolPref("aim.session.autologin", null, false);
  279.     document.getElementById('chkSavePassword').checked = savePassword;
  280.  
  281.     // PRASS TODO: This does something wrong. Keeps switching the pulldown incorrectly. Need to look into
  282.     // For now commenting out set menu pop up
  283.     var connectionName;
  284.   connectionName = aimPrefsManager().GetCharPref("aim.session.connectionname", null, false);
  285.   if (curScreenName) {
  286.         var connectionName;
  287.         if(doSNAndPasswd == true) {
  288.             connectionName = aimPrefsManager().GetCharPref("aim.session.connectionname", null, false);
  289.         }
  290.         else
  291.             connectionName = aimPrefsManager().GetCharPrefEdit("aim.session.connectionname", null, false, 
  292.                                                 curScreenName, -1);
  293.   //setMenuPopUp (connectionName);
  294.   }
  295.  
  296.     if(doSNAndPasswd == true && savePassword)
  297.         document.getElementById('fldPassword').value = password;
  298.     if (doSNAndPasswd == true && !savePassword)
  299.         document.getElementById('fldPassword').value = '';
  300.  
  301.  
  302.     document.getElementById('chkAutoLogin').checked = autoLogin;
  303.     EnableInputs();
  304. }
  305.  
  306.  
  307. function setMenuPopUp (pLabel){
  308.   
  309.   dump("starting setMenuPopUp pLabel=" + pLabel + "\n");
  310.     
  311.   if (!pLabel || pLabel == "") {
  312.     pLabel = "AIM";
  313.     }
  314.   var menuPopup = document.getElementById("sessionTypeList");
  315.   if (!menuPopup) {   
  316.     return;
  317.   }
  318.   var menuItems = menuPopup.childNodes;
  319.   var menuItem;
  320.   var defItem;
  321.   for (var i=0; i < menuItems.length; i++)
  322.   {
  323.     menuItem = menuItems.item(i);
  324.     if (menuItem.getAttribute("label") == pLabel )
  325.     {
  326.       document.getElementById('sessionTypeListmenu').selectedItem = menuItem;
  327.       UpdateCurrentWindow(pLabel);
  328.       return;
  329.     }
  330.     if (menuItem.getAttribute("label") == "AIM")  
  331.       defItem = menuItem;
  332.   }   
  333.     //default
  334.   document.getElementById('sessionTypeListmenu').selectedItem = defItem;
  335.   UpdateCurrentWindow(pLabel);
  336.   
  337. }
  338.  
  339. function SaveFieldsToPrefs() {
  340.   var screenName = document.getElementById('fldScreenName').value;
  341.   var password = document.getElementById('fldPassword').value;
  342.   var autoLogin = document.getElementById('chkAutoLogin').checked;
  343.   var savePassword = document.getElementById('chkSavePassword').checked;
  344.   var connectionNameNode = document.getElementById('sessionTypeListmenu').selectedItem;
  345.   var connectionName = connectionNameNode.getAttribute("label");
  346.  
  347.   //safety check for trying to save an "empty" screen name. 
  348.   if(screenName != ""){
  349.     aimPrefsManager().SetCharPref("aim.session.screenname", screenName, null, true);
  350.     aimPrefsManager().SetCharPref("aim.session.connectionname", connectionName, null, false);
  351.     //aimPrefsManager().SetCharPref("aim.session.userconnectionname", connectionName, null, true);
  352.  
  353.     // test screenname to see if there are any non-numeric chars
  354.     // if there are - then it's not a valid ICQ screen name so do not store it.
  355.     // if there are only numeric chars then it's not a valid AIM screen name since 
  356.     // they have to start with a letter at least.
  357.   
  358.     var foundNonNumeric = screenName.match(/[\D]+/g); //matches any alpha chars
  359.   
  360.     switch(connectionName){
  361.        case "ICQ": if(!foundNonNumeric){
  362.                       aimPrefsManager().SetCharPref("aim.session.latesticqscreenname", screenName, null, true);
  363.                       }
  364.                    break;
  365.        case "AIM": if(foundNonNumeric){
  366.                       aimPrefsManager().SetCharPref("aim.session.latestaimscreenname", screenName, null, true);
  367.                       }
  368.                    break;          
  369.   
  370.     }
  371.   }
  372.  
  373.  
  374.     if (savePassword)
  375.         aimSessionSavePassword(password);
  376.     else
  377.         aimSessionSavePassword("");
  378.  
  379.     aimPrefsManager().SetBoolPref("aim.session.storepassword", savePassword, null, false);
  380.     aimPrefsManager().SetBoolPref("aim.session.autologin", autoLogin, null, false);
  381. }
  382.  
  383.  
  384. function EnableInputs() {
  385.   var password = document.getElementById("fldPassword").value;
  386.     var savePassword = document.getElementById("chkSavePassword").checked;
  387.  
  388.     if (password != "") {
  389.     enableSignOnButton(true);
  390.     document.getElementById("chkSavePassword").disabled = false;
  391.         document.getElementById("chkAutoLogin").disabled = !savePassword;
  392.  
  393.         // XXX This is what the AIM 3.0 client does. Not sure if we should
  394.         //     change it.
  395.         if (!savePassword)
  396.             document.getElementById("chkAutoLogin").checked = false;
  397.     }
  398.     else {
  399.         enableSignOnButton(false);
  400.         document.getElementById("chkSavePassword").disabled = true;
  401.         document.getElementById("chkAutoLogin").disabled = true;
  402.  
  403.         // XXX This is what the AIM 3.0 client does. Not sure if we should
  404.         //     change it.
  405.         document.getElementById("chkSavePassword").checked = false;
  406.         document.getElementById("chkAutoLogin").checked = false;
  407.     }
  408. }
  409.  
  410.  
  411. /*
  412.  * Function: removeAllBuddyGroups()
  413.  *
  414.  * Arguments: none
  415.  * 
  416.  * Return: None
  417.  *
  418.  * Description: This function removes the IM datasource.
  419.  *
  420.  * Author: Suresh 12/13/01
  421.  */
  422.  
  423. function removeAllBuddyGroups()
  424. {
  425.   var aimbuddy = aimBuddyManager();
  426.   if (aimbuddy) {
  427.     aimbuddy.RemoveAllGroups();
  428.     aimbuddy.RemoveAuthGroup();
  429.   }
  430. }
  431.  
  432. /****************  RDF Observing ********************/
  433.  
  434. var OnlineObserver = new Object();
  435.  
  436. OnlineObserver.onAssert = function(datasource, source, property, target)
  437. {
  438.     if(source.EqualsNode(aimRDFSession()))
  439.     {
  440.         if(property.EqualsNode(aimRDFSessionState()))
  441.         {
  442.             var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  443.  
  444.             // flip to the appropriate panel in the deck
  445.       var deck = document.getElementById("PanelDeck");
  446.       var newIndex = deck.getAttribute("selectedIndex");
  447.       switch (state) {
  448.         case "Register":
  449.           setThrobberState(false);
  450.           newIndex = 4; // register panel
  451.           if  ((IsApp) && (!IsSidebar))  {
  452.               top.title = aimString("app.title.Register");
  453.               // top.document.getElementById("navigator-throbber").setAttribute("busy", "true");
  454.               }
  455.           break;
  456.         case "Offline":
  457.           setThrobberState(false);
  458.           var fsttry = aimPrefsManager().GetBoolPref("aim.session.firsttry", null, true);
  459.           if (!fsttry)       
  460.             newIndex = 0;// sign-on panel
  461.  
  462.           if  ((IsApp) && (!IsSidebar))  {
  463.               top.title = aimString("app.title.SignOn");
  464.               UpdateMenuItemsForApp(state);
  465.               }
  466.           break;
  467.         case "Online":
  468.           if (aimBuddyManager().GetBLLoadingState())
  469.             setThrobberState(true);
  470.           else
  471.             setThrobberState(false);
  472.           newIndex = 3; // online panel
  473.           if  ((IsApp) && (!IsSidebar))  {
  474.             if (isIcq() == true) {
  475.               top.title = aimString("app.title.Online_ICQ").replace(/%UserName%/, aimSessionCurrentScreenName());
  476.             }
  477.             else {
  478.               top.title = aimString("app.title.Online").replace(/%UserName%/, aimSessionCurrentScreenName());
  479.             }
  480.             // top.document.getElementById("navigator-throbber").setAttribute("busy", "false");
  481.             UpdateMenuItemsForApp(state);
  482.             if (initialState == "Offline")
  483.             {
  484.               openAIMToday();
  485.               initialState="Online";
  486.             }
  487.           }
  488.           if (isIcq() == true)
  489.           {
  490.             document.getElementById("ListSetup").setAttribute("context", "icqcontext");
  491.             document.getElementById("OnlineBuddies").setAttribute("context", "icqcontext");
  492.           }
  493.           else
  494.           {
  495.             document.getElementById("ListSetup").setAttribute("context", "context");
  496.             document.getElementById("OnlineBuddies").setAttribute("context", "context");
  497.           }
  498.           break;
  499.         case "OnlineAway":
  500.           setThrobberState(false);
  501.           newIndex = 2; // away panel
  502.           if  ((IsApp) && (!IsSidebar))
  503.             top.title = aimString("app.title.OnlineAway");
  504.           break;
  505.         case "Connecting":
  506.         case "Requesting":
  507.         case "Negotiating":
  508.         case "Validating":
  509.         case "Transferring":
  510.         case "Starting":
  511.           setThrobberState(true);
  512.           newIndex = 1; // connecting panel
  513.           if  ((IsApp) && (!IsSidebar))
  514.             top.title = aimString("app.title.Connecting");
  515.           newIndex = 1;
  516.       }
  517.       deck.setAttribute("selectedIndex", newIndex);
  518.       
  519.             if (state != "Offline" && state != "Online" && state != "Register" && state != "OnlineAway")
  520.             {
  521.         var str = aimString("btnSignOnProgress." + state);
  522.                 document.getElementById("btnSignOnProgress").setAttribute("value", str);
  523.                 var theProgressBar = document.getElementById("spconnectingprogressbar001");
  524.                 theProgressBar.setAttribute("value",parseInt(theProgressBar.getAttribute("value"))+15)
  525.             }
  526.       
  527.             if(state == "Online" || state == "OnlineAway")
  528.             {
  529.                     aimMigrateBuddyList( aimSessionCurrentScreenName() );
  530.             }
  531.       
  532.             // If returning to offline state, reinitialize the signon screen fields,
  533.             // which appear to be cleared out when they are hidden. We also do this
  534.             // when the form is loaded.
  535.             if (state == "Offline") {
  536.                 progress = window.document.getElementById("spconnectingprogressbar001");
  537.                       if ( progress && progress != undefined )
  538.                           progress.setAttribute("value", "0");
  539.                 InitFieldsFromPrefs(true, null);
  540.         initialState="Offline";
  541.         //this call is to delete all our datasources during signoff. Timeout is used coz the Signon panel
  542.         //must be loaded before we call this function. Without timeout, this function is called before the signon panel
  543.         //is loaded and it takes few seconds to see the panel :( 
  544.         setTimeout('removeAllBuddyGroups()', 500);
  545.         
  546.             }
  547.       
  548.             if (state == "Online") { 
  549.                 AimSidebarPanelSetAwayMsgBtn();    
  550.           UpdateUserWarning(null);
  551.           UpdateAuthAwaitGroup();
  552.           setTimeout('SelectIndex(0)', 2000);
  553.  
  554.           }
  555.       
  556.         }
  557.    
  558.    if(property.EqualsNode(aimRDFWarningStatus())) {
  559.       var st = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  560.       UpdateUserWarning(st);
  561.    }
  562.     
  563.     }
  564. };
  565.  
  566. OnlineObserver.onUnassert = function(datasource, source, property, target)
  567. {
  568.     // XXX Do we need to remove the attribute here ???
  569. };
  570.     
  571. OnlineObserver.onChange = function(datasource, source, property, oldTarget, newTarget)
  572. {
  573.     OnlineObserver.onAssert(datasource, source, property, newTarget);
  574. };
  575.     
  576. OnlineObserver.onMove = function(datasource, oldSource, newSource, property, target)
  577. {
  578.     OnlineObserver.onAssert(datasource, newSource, property, target);
  579. };
  580.  
  581. OnlineObserver.beginUpdateBatch = function(datasource)
  582. {
  583. };
  584.  
  585. OnlineObserver.endUpdateBatch = function(datasource)
  586. {
  587. };
  588.  
  589. /**************** Command Handlers ******************/
  590.  
  591. function cmdPanelSignOn() 
  592. {
  593.     SaveFieldsToPrefs();
  594.  
  595.     var screenName = document.getElementById('fldScreenName').value;
  596.     var password = document.getElementById('fldPassword').value;
  597.  
  598.     var curConnName = document.getElementById("sessionTypeListmenu").label;
  599.  
  600.     if (!IsServiceCorrect(screenName, curConnName)) {
  601.        return;  
  602.     }
  603.  
  604.   setConnectionInfo (curConnName, "im", screenName);
  605.     aimSessionLogin(screenName, password);
  606.       
  607. }
  608.  
  609.  
  610.  
  611.  
  612.  
  613. /************* key/focus handlers *************/
  614.  
  615. // function cmdScreenName(event)
  616. // handles key events from screenname field
  617. // id="fldScreenName shift-tabbing goes to id="sessionTypeListmenu"
  618. // id="fldScreenName" tabbing goes to id="fldPassword"
  619.  
  620. function cmdScreenName(event) {
  621.    var prevTabOrderElement = "sessionTypeListmenu";
  622.    var nextTabOrderElement = "fldPassword";
  623.    
  624.   if ((event.keyCode == 9) && (event.shiftKey)) 
  625.     {
  626.       document.getElementById(prevTabOrderElement).focus();
  627.       document.getElementById(prevTabOrderElement).setAttribute("focus-ring", "true");
  628.       event.preventDefault();
  629.       return;
  630.     }
  631.   
  632.     var screenName = document.getElementById('fldScreenName').value;
  633.   try {
  634.         var password = "";
  635.       try {
  636.         password = aimSessionGetPassword(screenName);
  637.         } catch (e) {}
  638.         document.getElementById('fldPassword').value = password; 
  639.         document.getElementById('fldPassword').setAttribute("value",password);
  640.     } catch (e) {dump("exception\n");}
  641.   EnableInputs();
  642.   InitFieldsFromPrefs(false, screenName);
  643.  
  644.   // if the user types in screenname and if find the password from pref, enable the send button.
  645.   if ((password.length != 0) && (screenName.length != 0))
  646.     enableSignOnButton(true);
  647.   else
  648.     enableSignOnButton(false);
  649.   // ..so.. if the user enters username and password is filled from prefs, then on enter key sign on.
  650.   if ((event.keyCode == 13) && (password.length != 0) && (screenName.length != 0))
  651.     cmdPanelSignOn();
  652.  
  653.   // if the user presses Enter and password field is empty, put the focus in password field.
  654.   if ((event.keyCode == 13) && (password.length == 0))
  655.     document.getElementById(nextTabOrderElement).focus();
  656. }
  657.  
  658. function cmdPasswordKeyup(event) {
  659.     // Enabled state of savePassword checkbox depends on
  660.     // empty/non-empty password field
  661.   EnableInputs();
  662.   InitFieldsFromPrefs(false, null);
  663.   var password = document.getElementById('fldPassword').value;
  664.   if (password.length > 0){
  665.     enableSignOnButton(true);
  666.     }
  667.   else{
  668.     enableSignOnButton(false);
  669.     }
  670. if (event.keyCode == 13 && password.length > 0){
  671.    event.preventDefault();
  672.    cmdPanelSignOn();
  673.    }
  674. }
  675.  
  676.  
  677. /*
  678.  * Function: setFocusPassLink (event)
  679.  *
  680.  * Arguments: 
  681.  *      event -- key event passed from SpSignOnOrgoverlay
  682.  *
  683.  * Return: None
  684.  *
  685.  * Description: This function intervenes the default focus propagation and sets focus 
  686.  * to the forgot password link to make it accessible. When user hits tab from the Signon button, the focus
  687.  * goes to forgot  password link. Tab from here, goes to screen name field and cycles as before.
  688.  *
  689.  */
  690.  
  691. function setFocusPassLink(event) {
  692.    var currTabOrderElement = "spsignonSignOn2";
  693.    var nextTabOrderElement = "spsignonpasslink";
  694.  
  695.   if (event.shiftKey) {
  696.     //go to previous element - either the sign on button or the help button
  697.     document.getElementById(currTabOrderElement).removeAttribute("focus-ring");
  698.     return;
  699.    }
  700.   event.preventDefault();
  701.   document.getElementById(currTabOrderElement).removeAttribute("focus-ring");
  702.   document.getElementById(nextTabOrderElement).focus();
  703.   document.getElementById(nextTabOrderElement).setAttribute("focus-ring", "true");  
  704.   
  705. }
  706.  
  707. /*
  708.  * Function: unsetFocusPassLink (event)
  709.  *
  710.  * Arguments: 
  711.  *      event -- key event passed from SpSignOnOrgoverlay
  712.  *
  713.  * Return: None
  714.  *
  715.  * Description: This function is called on the onkeypress handler on the password link label.
  716.  * If shift-tab is pressed, it puts focus on the Signon button (provided password field is not empty).
  717.  * If just tab is entered, then focus is put on the Screen name field by rotating focus in clockwise 
  718.  * direction.
  719.  *
  720.  */
  721.  
  722. function unsetFocusPassLink(event) {
  723.    var prevTabOrderElement = "spsignonSignOn2";
  724.    var currTabOrderElement = "spsignonpasslink";
  725.    var nextTabOrderElement = "spregisterpasslink";
  726.  
  727.   if (event.shiftKey) {
  728.     // Shift tab should rotate focus in anti clockwise direction. In this case focus to sign on button
  729.     var password = document.getElementById('fldPassword').value;
  730.     if (password.length == 0) 
  731.         // Do not put focus in sign on button is passfield field was empty - since user can use the button
  732.         return;
  733.     event.preventDefault();
  734.     document.getElementById(prevTabOrderElement).focus();
  735.     document.getElementById(prevTabOrderElement).setAttribute("focus-ring", "true");
  736.   }
  737.   document.getElementById(currTabOrderElement).removeAttribute('focus-ring');
  738. }
  739.  
  740. /*
  741.  * Function: setFocusRegisterLink (event)
  742.  *
  743.  * Arguments: 
  744.  *      event -- key event passed from SpSignOnOrgoverlay
  745.  *
  746.  * Return: None
  747.  *
  748.  * Description: This function intervenes the default focus propagation and sets focus 
  749.  * to the register user link to make it accessible. When user hits tab from the forgot password link, the focus
  750.  * goes to register link. Tab from here, goes to screen name field and cycles as before.
  751.  *
  752.  */
  753.  
  754. function setFocusRegisterLink(event) {
  755.    var prevTabOrderElement = "spsignonSignOn2";
  756.    var currTabOrderElement = "spsignonpasslink";
  757.    var nextTabOrderElement = "spregisterpasslink";
  758.  
  759.   if (event.shiftKey) {
  760.     document.getElementById(currTabOrderElement).removeAttribute("focus-ring");
  761.     document.getElementById(currTabOrderElement).blur();
  762.     return;
  763.    }
  764.   event.preventDefault();
  765.   document.getElementById(currTabOrderElement).removeAttribute("focus-ring");
  766.   document.getElementById(currTabOrderElement).blur();
  767.   document.getElementById(nextTabOrderElement).focus();
  768.   document.getElementById(nextTabOrderElement).setAttribute("focus-ring", "true");  
  769.   
  770. }
  771.  
  772. /*
  773.  * Function: unsetFocusRegisterLink (event)
  774.  *
  775.  * Arguments: 
  776.  *      event -- key event passed from SpSignOnOrgoverlay
  777.  *
  778.  * Return: None
  779.  *
  780.  * Description: This function is called on the onkeypress handler on the register user link label.
  781.  * If shift-tab is pressed, it puts focus on the forgot password link.
  782.  * If just tab is entered, then focus is put on the Screen name field by rotating focus in clockwise 
  783.  * direction.
  784.  *
  785.  */
  786.  
  787. function unsetFocusRegisterLink(event) {
  788.    var prevTabOrderElement = "spsignonpasslink";
  789.    var currTabOrderElement = "spregisterpasslink";
  790.    //var nextTabOrderElement = "sessionTypeListmenu";
  791.    if (event.shiftKey) {
  792.      event.preventDefault();
  793.      document.getElementById(prevTabOrderElement).focus();
  794.      document.getElementById(prevTabOrderElement).setAttribute("focus-ring", "true");
  795.    }
  796.    document.getElementById(currTabOrderElement).removeAttribute('focus-ring');
  797.    document.getElementById(currTabOrderElement).blur();
  798. }
  799.  
  800.  
  801. function setFocusSignOnButton(event){
  802.    var currTabOrderElement = "spsignonHelp2";
  803.    var nextTabOrderElement = "spsignonSignOn2";
  804.    if(event.shiftKey){
  805.       return;
  806.    }
  807.    if(document.getElementById(nextTabOrderElement).getAttribute("disabled") == "true"){
  808.       setFocusPassLink(event);
  809.    }else{
  810.      return;
  811.    }
  812.  
  813.  
  814. }
  815.  
  816.  
  817.  
  818.   /*
  819.   * Name: enableSignOnButton
  820.   *
  821.   * Arguments: flag. 
  822.   *
  823.   * Description:
  824.   *
  825.   * This function enables or disables the signon button based on the flag.
  826.   *    true = enables the button
  827.   *    false = disables the button
  828.   *
  829.   * Return Value: none
  830.   *
  831.   * Author: Suresh Kasinathan<suresh@netscape.com> 8/20/01
  832.   *
  833.   */
  834.  
  835. function enableSignOnButton(flag) {
  836.   var signOnButton = document.getElementById('spsignonSignOn2');
  837.   if (signOnButton) {
  838.     if (flag)
  839.       signOnButton.setAttribute("disabled", "false");
  840.     else
  841.       signOnButton.setAttribute("disabled", "true");
  842.   }
  843. }
  844.  
  845. function cmdClickSavePassword() {
  846.     if (!document.getElementById('chkSavePassword').checked)
  847.         aimPrefsManager().SetBoolPref("aim.session.storepassword", false, null, false);
  848.     // Enabled state of autoLogin checkbox depends on
  849.     // state of savePassword checkbox
  850.   EnableInputs();
  851.   // Save fields so that icq/aim switcher will pick up the checkbox pref.
  852.   SaveFieldsToPrefs();
  853. }
  854.  
  855. function cmdClickAutoLogin() {
  856. }
  857.  
  858. function cmdRegisterScreenName() {
  859.     var screenName = document.getElementById('fldRegisterName').value;
  860.  
  861.     if (screenName == '') {
  862.         aimErrorBox(aimString("msg.NoScreenName"));
  863.         return;
  864.     }
  865.   
  866.   // this will call into nsIAimSession, save the screen name in prefs and
  867.   // notify our observers to go from the register panel to the signon panel
  868.   aimSessionRegister(screenName);
  869.  
  870.     document.getElementById('fldScreenName').value = screenName;
  871. }
  872.  
  873. function cmdDoubleClick(event)
  874. {
  875.   if (event.button != 0) return;
  876.   var target = event.originalTarget;
  877.   if (event.detail == 2 && target.localName == "treechildren") {
  878.     var row = new Object;
  879.     var colID = new Object;
  880.     var childElt = new Object;
  881.  
  882.     var tree = getSelectedTreeName();
  883.     var col = getSelectedTabName();
  884.     if (!tree || !col) return;
  885.     tree.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject).getCellAt(event.clientX, event.clientY, row, colID, childElt);
  886.  
  887.     if (row.value == -1)
  888.       return;
  889.  
  890.     var view = tree.treeBoxObject.view;
  891.     var level = view.getLevel(row.value);
  892.     if (level == 0)
  893.       return;
  894.     var colvalue = document.getElementById(colID.value);
  895.     if (colvalue && colvalue.getAttribute("cycler") != "true" && (childElt.value != "twisty"))
  896.       cmdNewIM();
  897.   }
  898. }
  899.  
  900. function cmdFocus(event)
  901.     {
  902.     dump('focus: ' + event.target.tagName + '\n');
  903.     }
  904. function cmdBlur(event)
  905.     {
  906.     dump('blur: ' + event.target.tagName + '\n');
  907.     }
  908. function cmdGroupKeyUp(event)
  909.     {
  910.     if (event.keyCode == 13)
  911.         {
  912.         var item = event.target.parentNode.parentNode.parentNode;
  913.         var name = item.getAttribute('Name');
  914.         var newName = event.target.value;
  915.  
  916.         aimBuddyRenameBuddyGroup(name, newName);
  917.         }
  918.     }
  919. function cmdBuddyKeyUp(event)
  920.     {
  921.     if (event.keyCode == 13)
  922.         {
  923.         var item = event.target.parentNode.parentNode.parentNode;
  924.         var screenName = item.getAttribute('ScreenName');
  925.         var newName = event.target.value;
  926.  
  927.         var groupItem = item.parentNode.parentNode;
  928.         var groupName = groupItem.getAttribute('Name');
  929.  
  930.         var nextBuddy = null;
  931.         if (item.nextSibling)
  932.             nextBuddy = item.nextSibling.getAttribute('ScreenName');
  933.  
  934.         // XXX aimBuddyReplaceBuddy(groupName, screenName, newName);
  935.         aimBuddyRemoveBuddy(groupName, screenName);
  936.         aimBuddyAddBuddy(groupName, newName, nextBuddy);
  937.         }
  938.     }
  939. function spInPlaceAddBuddy()
  940.     {
  941.       spInPlaceAddDelete( "AddBuddy" );
  942.     }
  943. function spAddBuddy()
  944.     {
  945.     val = prompt( "Enter Buddy Name","" );
  946.     }
  947. function spAddGroup()
  948.     {
  949.     val = prompt( "Enter Group Name", "" );
  950.     }
  951. function spInPlaceAddGroup()
  952.     {
  953.         spInPlaceAddDelete( "AddGroup" );
  954.     }
  955. function spInPlaceDelete()
  956.     {
  957.       spInPlaceAddDelete( "Delete" );
  958.     }
  959.  
  960. function spInPlaceAddDelete( what )    // "Delete", "AddGroup", "AddBuddy"
  961.     {
  962.     // Locate selection in setup list
  963.     // XXX There must be a better way to do this
  964.     var selectedGroup = null;
  965.     var selectedBuddy = null;
  966.     var tree = document.getElementById("ListSetup");
  967.     var groups = tree.childNodes[2].childNodes;
  968.     for (var i = 0; i != groups.length; i++)
  969.         {
  970.         if (groups[i].getAttribute("selected") == "true")
  971.             {
  972.             selectedGroup = groups[i].getAttribute("Name");
  973.             break;
  974.             }
  975.  
  976.         var buddies = null;
  977.         for (var j = 0; j != groups[i].childNodes.length; j++)
  978.             {
  979.             if (groups[i].childNodes[j].nodeName == "treechildren")
  980.                 {
  981.                 buddies = groups[i].childNodes[j].childNodes;
  982.                 break;
  983.                 }
  984.             }
  985.  
  986.         if (buddies)
  987.             {
  988.             for (var j = 0; j != buddies.length; j++)
  989.                 {
  990.                 if (buddies[j].getAttribute("selected") == "true")
  991.                     {
  992.                     selectedBuddy = buddies[j].getAttribute("ScreenName");
  993.                     break;
  994.                     }
  995.                 }
  996.  
  997.             if (selectedBuddy)
  998.                 {
  999.                 selectedGroup = groups[i].getAttribute("Name");
  1000.                 break;
  1001.                 }
  1002.             }
  1003.         }
  1004.  
  1005.     if (what == "AddBuddy")
  1006.         aimBuddyAddBuddy(selectedGroup, null, selectedBuddy);
  1007.     else if (what == "AddGroup")
  1008.         aimBuddyAddBuddyGroup(null, selectedGroup);
  1009.     else if (what == "Delete")
  1010.         {
  1011.         if (selectedBuddy)
  1012.             aimBuddyRemoveBuddy(selectedGroup, selectedBuddy);
  1013.         else if (selectedGroup)
  1014.             aimBuddyRemoveBuddyGroup(selectedGroup);
  1015.         }
  1016.     }
  1017.  
  1018. function spFindEmpty( display )    
  1019. {
  1020.     // Locate selection in setup list
  1021.     // XXX There must be a better way to do this
  1022.     var selectedGroup = null;
  1023.     var selectedBuddy = null;
  1024.     var tree = document.getElementById("ListSetup");
  1025.     var groups = tree.childNodes[2].childNodes;
  1026.  
  1027.     
  1028.     for (var i = 0; i != groups.length; i++)
  1029.     {
  1030.         var buddies = null;
  1031.         for (var j = 0; j != groups[i].childNodes.length; j++)
  1032.         {
  1033.             if (groups[i].childNodes[j].nodeName == "treechildren")
  1034.             {
  1035.                 buddies = groups[i].childNodes[j].childNodes;
  1036.                 break;
  1037.             }
  1038.         }
  1039.  
  1040.         if (buddies)
  1041.         {
  1042.             for (var j = 0; j != buddies.length; j++)
  1043.             {
  1044.                 if (buddies[j].getAttribute("ScreenName") == "")
  1045.                 {
  1046.                     selectedBuddy = buddies[j];
  1047.                     if ( display == "none" ) {
  1048.                         selectedBuddy.setAttribute("style", "visibility: hidden;");
  1049.                         selectedBuddy.setAttribute("Yabba", "Dabba;");
  1050.                     }
  1051.                     else {
  1052.                         selectedBuddy.setAttribute("style", "visibility: visible;");
  1053.                     }
  1054.                 }
  1055.                 if (buddies[j].getAttribute("type") == "text")
  1056.                 {
  1057.                     //dump( "Found an object that has a type of 'text'\n" );
  1058.                 }
  1059.             }
  1060.         }
  1061.     }
  1062.  
  1063.     //dump('  selectedGroup: ' + selectedGroup + '\n');
  1064.     //dump('  selectedBuddy: ' + selectedBuddy + '\n');
  1065. }
  1066. /*
  1067. function displayFrontTab(tabObj)
  1068. {
  1069.     tabOne=document.getElementById('tabOnline');
  1070.     tabTwo=document.getElementById('tabSetup');
  1071.     tabOne.setAttribute("style","");
  1072.     tabTwo.setAttribute("style","");
  1073.     tabObj.setAttribute("style","");
  1074. }
  1075.  
  1076. */
  1077.  
  1078. /*** setup chat callbacks for rendezvous ***/
  1079. /** start services **/
  1080. var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  1081. var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager);
  1082. var ChatManager = pIIMManager.QueryInterface(Components.interfaces.nsIAimChatManager);
  1083.  
  1084. /*** setup the chat call backs **/
  1085.  var ChatCallback = new Object();
  1086.  
  1087.  ChatCallback.OnRequestRoomComplete =  function(roomName,chatRoomObj){
  1088.   
  1089.   chatRoomObj.SetChatRoomCallback(ChatRoomCallback);
  1090.  
  1091.  top.chatRoomObj = chatRoomObj;
  1092.   window.setTimeout('top.chatRoomObj.Join()', 5000);
  1093.   window.setTimeout('top.chatRoomObj.Invite("vishy26aug", "Join this MAAN")', 10000);
  1094.   window.setTimeout('top.chatRoomObj.SendMessage("This is working!!")', 30000);
  1095.   window.setTimeout('top.chatRoomObj.SendWhisper("vishy26aug", "Private message for vishy26aug")', 30000);
  1096.  }
  1097.  
  1098.  
  1099.  ChatCallback.OnRequestRoomError =  function(roomName,errMsg){
  1100.  //dump("OnRequestRoomError: there was an error \n");
  1101.  
  1102.  }
  1103.  
  1104. /** setup the chat Room callbacks **/
  1105.  
  1106.  var ChatRoomCallback = new Object();
  1107.  
  1108.  ChatRoomCallback.OnJoined = function()
  1109.  {
  1110.   //dump("Yes I Joined\n");
  1111.  }
  1112.  
  1113.  ChatRoomCallback.OnUserJoined = function(screenName)
  1114.  {
  1115.   //dump( screenName + "joined the chat\n");
  1116.  }
  1117.  
  1118.  ChatRoomCallback.OnInfoUpdate = function()
  1119.  {
  1120.  }
  1121.  
  1122.  ChatRoomCallback.OnMessageReceived = function(screenName, language, message)
  1123.  {
  1124.   //dump (screenName + " SAYETH " + message + " IN " + language +"\n");
  1125.  }
  1126.  
  1127.  
  1128.  
  1129. var rendezvousCallback = new Object();
  1130.  
  1131. rendezvousCallback.OnProposalReceived = function (screenname, proposal)
  1132. {
  1133.     //dump ("got a proposal from " + screenname + "\n");
  1134.  
  1135.      //proposal.Accept();
  1136.      inviteArgsObj = {
  1137.          inviteProposalScreenName: screenname, 
  1138.          inviteProposalObj: proposal,
  1139.          invitedScreenNames: '',
  1140.          inviteToExistingWindow: false,
  1141.          inviteMode: 'incomingchat'
  1142.          }
  1143.      //dump('send proposal to dialog! \n;')
  1144.     window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj); 
  1145.     
  1146.      //dump("accepted the proposal");
  1147.  
  1148.      //ChatManager.RequestProposedRoom(ChatCallback, proposal);
  1149.  
  1150.  }
  1151.  
  1152. function setupChatRendezvous(){
  1153.     //dump("entering setupChatRendezvous 3\n");
  1154.     ChatManager.SetChatRendezvousCallback(rendezvousCallback)
  1155.     //dump("exiting setupChatRendezvous \n");
  1156. }
  1157.  
  1158.  
  1159. /***  end setup chat callbacks for rendezvous ***/
  1160.  
  1161. function cmdNewChatSidebar(invScreenName,invProposal,invScreenNames,toExistingWindow,invMode){
  1162.  
  1163.      inviteArgsObj = {
  1164.          inviteProposalScreenName: invScreenName, 
  1165.          inviteProposalObj: invProposal,
  1166.          invitedScreenNames: getSelectedBuddiesFromList(), //invScreenNames, (getSelectedBuddiesFromList is in App.js)
  1167.          inviteToExistingWindow: toExistingWindow,
  1168.          inviteMode: invMode
  1169.          }
  1170.          
  1171.     window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  1172. }
  1173.  
  1174. // Function to open a new window for password lookup
  1175. function openPassLink()
  1176. {
  1177.   var checkSession=document.getElementById("sessionWatcher").getAttribute('sessionMode'); 
  1178.   if (checkSession == "Aim") {
  1179.     passLink = aimString("aim.password.url");
  1180.     openTopWin(passLink);
  1181.     return;
  1182.   }
  1183.   else {
  1184.     passLink = aimString("icq.password.url");
  1185.     openTopWin(passLink);  
  1186.     }
  1187.   
  1188. }
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194. /*
  1195.  * Function:  UpdateAuthAwaitGroup()
  1196.  *
  1197.  * Arguments: None
  1198.  *
  1199.  * Return: None
  1200.  *
  1201.  * 
  1202.  * Author: Prassanna 4/06/2002
  1203.  */
  1204.  
  1205. function UpdateAuthAwaitGroup()
  1206. {
  1207.   if (isIcq() == true) {
  1208.     // Session is ICQ. Show Auth Await Group.
  1209.     document.getElementById('AuthAwait1').setAttribute("hidden", "false");
  1210.     document.getElementById('AuthAwait2').setAttribute("hidden", "false");
  1211.   }
  1212.   else
  1213.   {
  1214.     // Session is AIM. Hide Auth Await Group.
  1215.     document.getElementById('AuthAwait1').setAttribute("hidden", "true");
  1216.     document.getElementById('AuthAwait2').setAttribute("hidden", "true");
  1217.   }
  1218. }
  1219.  
  1220. function UpdateUserWarning(warning)
  1221. {
  1222.   var name = document.getElementById("warnname");
  1223.   var warn = document.getElementById("warnamount");
  1224.   if (warning != null)
  1225.   {
  1226.     if (warning > 0)
  1227.     {
  1228.       warn.setAttribute("value", " " + warning + "%");
  1229.       name.setAttribute("class", "warned");
  1230.     }
  1231.     else
  1232.     {
  1233.       warn.setAttribute("value", "");
  1234.       name.setAttribute("class", "not-warned");
  1235.     }
  1236.     
  1237.     return
  1238.   }
  1239.   
  1240.   var curname=aimSessionCurrentScreenName();
  1241.  
  1242.   //document.getElementById("warnConnIcon").setAttribute("sessionType", aimPrefsManager().GetIntPref("aim.internal.intconnectiontype", null, true) );
  1243.  
  1244.   name.setAttribute("value",curname);
  1245.   
  1246.   var locateManager = aimLocateManager();
  1247.   var LocateCallbackObject = new Object();
  1248.   
  1249.   LocateCallbackObject.OnRequestUserInfoDefaultComplete = function(screenname, userobj)
  1250.   {
  1251.     var percent = userobj.GetWarningPercent();
  1252.     if (percent > 0 )
  1253.     {
  1254.       warn.setAttribute("value", " - " + percent + "%");
  1255.       name.setAttribute("class", "warned");
  1256.     }
  1257.     else
  1258.     {
  1259.       warn.setAttribute("value", "");
  1260.       name.setAttribute("class", "not-warned");
  1261.     }
  1262.   }
  1263.  
  1264.   LocateCallbackObject.OnRequestUserInfoDefaultError = function(screenname, error)
  1265.   {
  1266.     //nothing
  1267.   }
  1268.   
  1269.   if (navigator.platform != "MacPPC")
  1270.   {
  1271.     locateManager.RequestUserInfoDefault( LocateCallbackObject, curname);
  1272.   }
  1273. }
  1274.  
  1275.  
  1276. /*
  1277.  * Function: SetProcessTimer( interval )
  1278.  *
  1279.  * Arguments: 
  1280.  *      interval -- timeout in milliseconds 
  1281.  *
  1282.  * Return: None
  1283.  *
  1284.  * Description: This function sets the global (to App.js) timer 
  1285.  * processInviteTimer to fire after the specified interval
  1286.  *
  1287.  * Author: Syd 4/20/2001
  1288.  */
  1289.  
  1290. function SetProcessTimer( interval )
  1291. {
  1292.   processInviteTimer = setTimeout('ProcessInviteList()',interval);
  1293. }
  1294.  
  1295. /*
  1296.  * Function: ClearProcessTimer()
  1297.  *
  1298.  * Arguments: None
  1299.  *
  1300.  * Return: None
  1301.  *
  1302.  * Description: if the global processInviteTimer != -1, then
  1303.  * clear the timer, otherwise return. This function should 
  1304.  * be called by the onunload handler or at anytime the state
  1305.  * goes from online to offline
  1306.  *
  1307.  * Author: Syd 4/20/2001
  1308.  */
  1309.  
  1310. function ClearProcessTimer()
  1311. {
  1312.         if ( processInviteTimer != -1 ) {
  1313.                 window.clearTimeout( processInviteTimer );
  1314.                 processInviteTimer = -1;
  1315.         }
  1316. }
  1317.  
  1318.  
  1319.  
  1320. /*
  1321.  * Function: aimToday ()
  1322.  *
  1323.  * Arguments: None
  1324.  *
  1325.  * Return: None
  1326.  *
  1327.  * Description: This function launches the aimToday window.
  1328.  *
  1329.  */
  1330.  
  1331. function aimToday()
  1332. {
  1333.   var todayhide = aimPrefsManager().GetBoolPref("aim.internal.hidetoday", null, false);
  1334.   if (!todayhide)
  1335.   {
  1336.     var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  1337.     var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
  1338.     var topWindow = windowManagerInterface.getMostRecentWindow( "mini:browser" );
  1339.     if ( topWindow )
  1340.     {
  1341.       topWindow.focus();
  1342.     }
  1343.     else
  1344.     {
  1345.       window.open("chrome://aim/content/mini.xul", "_blank", "chrome,extrachrome,menubar,resizable=no,status,toolbar");
  1346.     }
  1347.   }
  1348. }
  1349.  
  1350. function setFocusIfSignOnDisabled(event){
  1351.   if ((event.keyCode == 9) && (document.getElementById('spsignonSignOn2').getAttribute('disabled') == 'true')) {
  1352.     document.getElementById("spsignonHelp2").blur();
  1353.     setFocusPassLink(event)
  1354.   };
  1355. }
  1356.  
  1357.  
  1358. /*
  1359.  * Function: UpdateSessionImages(sessionType)
  1360.  *
  1361.  * Arguments: 
  1362.  *      sessionType -- "0" is Aim, "1" is TIH and "2" is Icq. Value passed from the Service selection 
  1363.  *                      pop-up menu.
  1364.  *
  1365.  * Return: None
  1366.  *
  1367.  * Description: This function sets the users choice of sessionType in the global pref. It also notifies all the observers
  1368.  * who are watching for the session-Mode changed message about the user's choice of service.
  1369.  *
  1370.  * Author: Prassanna 4/02/2002
  1371.  */
  1372.  
  1373. function UpdateSessionImages(sessionType)
  1374. {
  1375.   var session="";
  1376.   var connectionNameNode = document.getElementById('sessionTypeListmenu').selectedItem;
  1377.   var connectionName = connectionNameNode.getAttribute("label");
  1378.   aimPrefsManager().SetCharPref("aim.session.userconnectionname", connectionName, null, true);
  1379.   aimSession().SetAppIcon();
  1380.   var latestScreenNameOfType = aimPrefsManager().GetCharPref("aim.session.screenname", null, true);
  1381.  
  1382.   switch (sessionType) {
  1383.         case "2": session="Icq";
  1384.                   latestScreenNameOfType = aimPrefsManager().GetCharPref("aim.session.latesticqscreenname",null, true);
  1385.                   //changeTitle("Contact List");
  1386.                   break;
  1387.         case "0": session="Aim";
  1388.                   latestScreenNameOfType = aimPrefsManager().GetCharPref("aim.session.latestaimscreenname",null, true);
  1389.                   //changeTitle("Buddy List");
  1390.                   break;   
  1391.   }
  1392.  
  1393.   /** start update sign on fields due to  sessionChange **/
  1394.   aimPrefsManager().SetCharPref("aim.session.screenname", latestScreenNameOfType, null, true);
  1395.   InitFieldsFromPrefs( true, latestScreenNameOfType)
  1396.   /** end update **/
  1397.    var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  1398.   observerService.notifyObservers(null, "sessionMode-changed", session);
  1399. }
  1400.  
  1401.  
  1402.  
  1403. /*
  1404.  * Function: UpdateCurrentWindow(sessionName)
  1405.  *
  1406.  * Arguments: 
  1407.  *      sessionName -- "Aim" or "Icq". passed when the current pop label is set
  1408.  *
  1409.  * Return: None
  1410.  *
  1411.  * Description: This function is called on load of sidebar buddy list. It basically sets 
  1412.  * sessionMode attribute on the broadcaster element when the apropriate seesin label is being set. 
  1413.  * This is done so that the current window  and the elements reflect the current sessionName.
  1414.  *
  1415.  * Author: Prassanna 4/02/2002
  1416.  */
  1417.  
  1418. function UpdateCurrentWindow(sessionName)
  1419. {
  1420.   var session;
  1421.   var elems = document.getElementById("sessionWatcher");
  1422.   switch (sessionName) {
  1423.         case "ICQ": session="Icq";
  1424.                     elems.setAttribute("sessionMode", "Icq"); 
  1425.                     break;
  1426.         case "AIM": session="Aim";
  1427.                     elems.setAttribute("sessionMode", "Aim"); 
  1428.                     break;   
  1429.   }
  1430.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  1431.   observerService.notifyObservers(null, "sessionMode-changed", session);
  1432. }
  1433.  
  1434.  
  1435.  
  1436. /*
  1437.  * Function: addSidebarSessionListener
  1438.  *
  1439.  * Arguments: None
  1440.  *
  1441.  * Return: None
  1442.  *
  1443.  * Description: This function is called on the load of sidebar buddylist panel. This adds a sessionSidebarObserver 
  1444.  * which waits for the sessionMode-changed message.
  1445.  *
  1446.  * Author: Prassanna 4/02/2002
  1447.  */
  1448.  
  1449. function addSidebarSessionListener() {
  1450.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1451.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1452.   if (observerService) {
  1453.     observerService.addObserver(sessionSidebarObserver, "sessionMode-changed", false);
  1454.   } else {
  1455.     dump("failed to get observer service\n");
  1456.   }
  1457. }
  1458.  
  1459. /*
  1460.  * Function: removeSidebarSessionListener
  1461.  *
  1462.  * Arguments: None
  1463.  *
  1464.  * Return: None
  1465.  *
  1466.  * Description: This function is called on the Unload of sidebar buddylist panel. This removes the existing sessionSidebarObserver 
  1467.  * on the current sidebarpanel.
  1468.  *
  1469.  * Author: Prassanna 4/02/2002
  1470.  */
  1471.  
  1472. function removeSidebarSessionListener() {
  1473.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1474.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1475.   if (observerService)
  1476.   {
  1477.   observerService.removeObserver(sessionSidebarObserver, "sessionMode-changed");
  1478.   }
  1479. }
  1480.  
  1481. /*
  1482.  * Function: UpdateSidebarLabels(sessionName)
  1483.  *
  1484.  * Arguments: sessionName - Passed from the listener. Aim/Icq
  1485.  *
  1486.  * Return: None
  1487.  *
  1488.  * Description: This function is called when the notifier receives sessionMode changed notification. It bruteforces all
  1489.  * the UI widgets to have the appropriate display labels and tooltips based on sessionName.
  1490.  *
  1491.  * Author: Prassanna 4/02/2002
  1492.  */
  1493.  
  1494.  
  1495. function UpdateSidebarLabels(sessionName)
  1496. {
  1497.   switch (sessionName) {
  1498.         case "Icq": var icqval=  document.getElementById('sessionTypeIcq').getAttribute("label");
  1499.                     document.getElementById('sessionTypeListmenu').setAttribute("label",icqval);
  1500.                     document.getElementById('sessionTypeListmenu').setAttribute("value","2");
  1501.                     icqval=document.getElementById('btnbuddyorgsendim').getAttribute("icqtooltip");
  1502.                     document.getElementById('btnbuddyorgsendim').setAttribute("tooltiptext", icqval);
  1503.                     //icqval=document.getElementById('tabOnline').getAttribute("icqlabel");
  1504.                     //document.getElementById('tabOnline').setAttribute("label", icqval);
  1505.                     //icqval=document.getElementById('tabSetup').getAttribute("icqlabel");
  1506.                     //document.getElementById('tabSetup').setAttribute("label", icqval);
  1507.                     icqval=document.getElementById('btnbuddyorgsignoff').getAttribute("icqlabel");
  1508.                     document.getElementById('btnbuddyorgsignoff').setAttribute("label", icqval);
  1509.                     icqval=document.getElementById('btnbuddyorgsignoff').getAttribute("icqtooltip");
  1510.                     document.getElementById('btnbuddyorgsignoff').setAttribute("tooltiptext", icqval);
  1511.                     icqval=document.getElementById('btnSignOnCancel').getAttribute("icqtooltip");
  1512.                     document.getElementById('btnSignOnCancel').setAttribute("tooltiptext", icqval); 
  1513.                     icqval=document.getElementById('snid').getAttribute("icqlabel");
  1514.                     document.getElementById('snid').setAttribute("value", icqval);   
  1515.                     icqval=document.getElementById('chkAutoLogin').getAttribute("icqlabel");
  1516.                     document.getElementById('chkAutoLogin').setAttribute("label", icqval);   
  1517.                     icqval=document.getElementById('spsignonHelp2').getAttribute("icqtooltip");
  1518.                     document.getElementById('spsignonHelp2').setAttribute("tooltiptext", icqval);
  1519.                     icqval=document.getElementById('spsignonSignOn2').getAttribute("icqlabel");
  1520.                     document.getElementById('spsignonSignOn2').setAttribute("label", icqval);   
  1521.                     icqval=document.getElementById('spsignonSignOn2').getAttribute("icqtooltip");
  1522.                     document.getElementById('spsignonSignOn2').setAttribute("tooltiptext", icqval);
  1523.                     icqval=document.getElementById('spregisterpasslink').getAttribute("icqlabel");
  1524.                     document.getElementById('spregisterpasslink').setAttribute("value", icqval);   
  1525.                     icqval=document.getElementById('spregisterpasslink').getAttribute("icqtooltip");
  1526.                     document.getElementById('spregisterpasslink').setAttribute("tooltiptext", icqval);
  1527.                     icqval=document.getElementById('btnsetuporgbuddy').getAttribute("icqtooltip");
  1528.                     document.getElementById('btnsetuporgbuddy').setAttribute("tooltiptext", icqval);
  1529.                     icqval=document.getElementById('btnsetuporgdelete').getAttribute("icqtooltip");
  1530.                     document.getElementById('btnsetuporgdelete').setAttribute("tooltiptext", icqval);
  1531.                     icqval=document.getElementById('btnImBack').getAttribute("icqlabel");
  1532.                     document.getElementById('btnImBack').setAttribute("label", icqval);
  1533.                     var sidebarimpanel = top.document.getElementById('urn:sidebar:panel:im-panel');
  1534.                     if (sidebarimpanel)
  1535.                       sidebarimpanel.setAttribute("label", aimString("icq.sidebarTitle"));
  1536.                     break;
  1537.         case "Aim": var aimval=  document.getElementById('sessionTypeAim').getAttribute("label");
  1538.                     document.getElementById('sessionTypeListmenu').setAttribute("label",aimval);
  1539.                     document.getElementById('sessionTypeListmenu').setAttribute("value","0");
  1540.                     aimval=document.getElementById('btnbuddyorgsendim').getAttribute("imtooltip");
  1541.                     document.getElementById('btnbuddyorgsendim').setAttribute("tooltiptext", aimval);
  1542.                     //aimval=document.getElementById('tabOnline').getAttribute("imlabel");
  1543.                     //document.getElementById('tabOnline').setAttribute("label", aimval);
  1544.                     //aimval=document.getElementById('tabSetup').getAttribute("imlabel");
  1545.                     //document.getElementById('tabSetup').setAttribute("label", aimval);
  1546.                     aimval=document.getElementById('btnbuddyorgsignoff').getAttribute("imlabel");
  1547.                     document.getElementById('btnbuddyorgsignoff').setAttribute("label", aimval);
  1548.                     aimval=document.getElementById('btnbuddyorgsignoff').getAttribute("imtooltip");
  1549.                     document.getElementById('btnbuddyorgsignoff').setAttribute("tooltiptext", aimval);
  1550.                     aimval=document.getElementById('btnSignOnCancel').getAttribute("imtooltip");
  1551.                     document.getElementById('btnSignOnCancel').setAttribute("tooltiptext", aimval); 
  1552.                     aimval=document.getElementById('snid').getAttribute("imlabel");
  1553.                     document.getElementById('snid').setAttribute("value", aimval);   
  1554.                     aimval=document.getElementById('chkAutoLogin').getAttribute("imlabel");
  1555.                     document.getElementById('chkAutoLogin').setAttribute("label", aimval);   
  1556.                     aimval=document.getElementById('spsignonHelp2').getAttribute("imtooltip");
  1557.                     document.getElementById('spsignonHelp2').setAttribute("tooltiptext", aimval);
  1558.                     aimval=document.getElementById('spsignonSignOn2').getAttribute("imlabel");
  1559.                     document.getElementById('spsignonSignOn2').setAttribute("label", aimval);   
  1560.                     aimval=document.getElementById('spsignonSignOn2').getAttribute("imtooltip");
  1561.                     document.getElementById('spsignonSignOn2').setAttribute("tooltiptext", aimval);
  1562.                     aimval=document.getElementById('spregisterpasslink').getAttribute("imlabel");
  1563.                     document.getElementById('spregisterpasslink').setAttribute("value", aimval);   
  1564.                     aimval=document.getElementById('spregisterpasslink').getAttribute("imtooltip");
  1565.                     document.getElementById('spregisterpasslink').setAttribute("tooltiptext", aimval);
  1566.                     aimval=document.getElementById('btnsetuporgbuddy').getAttribute("imtooltip");
  1567.                     document.getElementById('btnsetuporgbuddy').setAttribute("tooltiptext", aimval);
  1568.                     aimval=document.getElementById('btnsetuporgdelete').getAttribute("imtooltip");
  1569.                     document.getElementById('btnsetuporgdelete').setAttribute("tooltiptext", aimval);
  1570.                     aimval=document.getElementById('btnImBack').getAttribute("imlabel");
  1571.                     document.getElementById('btnImBack').setAttribute("label", aimval);
  1572.                     var sidebarimpanel = top.document.getElementById('urn:sidebar:panel:im-panel');
  1573.                     if (sidebarimpanel)
  1574.                       sidebarimpanel.setAttribute("label", aimString("importexport.budlist"));
  1575.                     break;   
  1576.   }
  1577.   
  1578. }
  1579.  
  1580.  
  1581. /*
  1582.  * Function: observe
  1583.  *
  1584.  * Arguments: message - "sessionMode-changed"
  1585.  *              data - "Aim/Icq"
  1586.  *              passed by the notifier 
  1587.  *
  1588.  * Return: None
  1589.  *
  1590.  * Description: This function updates the sessionWatcher broadcaster with the passes sessionMode. It forces the css
  1591.  * to apply the image rules based on sessionMode attribute. It also  calls the UpsideSidebarLabels with the sessionMode
  1592.  * so that all the labels and tooltips are updated based on the sessionMode.
  1593.  *
  1594.  * Author: Prassanna 4/02/2002
  1595.  */
  1596.  
  1597. var sessionSidebarObserver = {
  1598.   observe: function(subject, message, data) {
  1599.   if (message == 'sessionMode-changed')  {
  1600.      // Update sessionMode attribute which updates all images thru css
  1601.      document.getElementById("sessionWatcher").setAttribute("sessionMode", data);
  1602.     // Update all strings and labels to workaround un-dynamic dtd:-(
  1603.      UpdateSidebarLabels(data);
  1604.      }
  1605.   }
  1606. }
  1607.  
  1608.  
  1609. /*
  1610.  * Function: getDs()
  1611.  *
  1612.  * Arguments: None
  1613.  *
  1614.  * Return: sidebar panel datasource
  1615.  *
  1616.  * Description: This function is called by the changeTitle function to obtain the sidebar datasource.
  1617.  *
  1618.  * Author: Prassanna 4/02/2002
  1619.  */
  1620.  
  1621. function getDs()
  1622. {
  1623.   var PANELS_RDF_FILE = "UPnls";
  1624.   try 
  1625.   {
  1626.     var locator_service = Components.classes["@mozilla.org/file/directory_service;1"].getService();
  1627.     if (locator_service)
  1628.       locator_service = locator_service.QueryInterface(Components.interfaces.nsIProperties);
  1629.       var sidebar_file = locator_service.get(PANELS_RDF_FILE, Components.interfaces.nsIFile);
  1630.     if (!sidebar_file.exists()) {
  1631.       //Sidebar panels file does not exist?
  1632.       return;
  1633.     }
  1634.         var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  1635.         file_url.file = sidebar_file;
  1636.       return file_url.spec;
  1637.   } catch (ex) {
  1638.      throw(ex);
  1639.   }
  1640. }
  1641.  
  1642. /*
  1643.  * Function:  changeTitle(title)
  1644.  *
  1645.  * Arguments: title - the title for the instant messenger sidebarpanel  "BuddyList"/"ContactList"
  1646.  *
  1647.  * Return: None
  1648.  *
  1649.  * Description: This function is during UpdateSidebarLabels upon notification of session Change. This attempts to
  1650.  * change the title of the instant messenger sidebar panel  basedon user's service choice Aim/Icq
  1651.  *
  1652.  * Author: Prassanna 4/02/2002
  1653.  */
  1654.  
  1655.  
  1656. function changeTitle(title)
  1657. {
  1658.  
  1659.   var RDF = aimRDF();
  1660.   const NC = "http://home.netscape.com/NC-rdf#";
  1661.   var panels = window.parent.document.getElementById("sidebar-panels");
  1662.   var datasource = RDF.GetDataSource(getDs());
  1663.   //var datasource = panels.database;
  1664.  
  1665.   var persistNode = datasource.GetTarget(RDF.GetResource("urn:sidebar:panel:im-panel"),  RDF.GetResource(NC + "title"),true);
  1666.   if (persistNode)
  1667.   {
  1668.     datasource.Change(RDF.GetResource("urn:sidebar:panel:im-panel"),
  1669.                                     RDF.GetResource(NC + "title"), 
  1670.                                     persistNode,
  1671.                                     RDF.GetLiteral(title));
  1672.     
  1673. /*
  1674.     panels.setAttribute('ref', "urn:sidebar:current-panel-list");
  1675.     panels.setAttribute('last-selected-panel', "urn:sidebar:panel:im-panel");
  1676.     SidebarRebuild();
  1677.     for (var ii=2; ii < panels.childNodes.length; ii += 2) {
  1678.           var header = panels.childNodes.item(ii);
  1679.           var content = this.node.childNodes.item(ii+1);
  1680.           if (header.getAttribute('id') == "urn:sidebar:panel:im-panel") {
  1681.                header.setAttribute('selected', 'true');
  1682.                content.removeAttribute('hidden');
  1683.                content.removeAttribute('collapsed');
  1684.                header.reload();
  1685.          break;
  1686.         }
  1687.     }
  1688.  
  1689. // After setting the current panel disappears from view :-( Have to reload maunally. Commenting for now
  1690.   datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1691.   datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Refresh(true);
  1692. */
  1693.   }
  1694.     
  1695.                    
  1696. }
  1697.  
  1698.  
  1699. /*
  1700.  * Function: addSidebarBuddyListObserver
  1701.  *
  1702.  * Arguments: None
  1703.  *
  1704.  * Return: None
  1705.  *
  1706.  * Description: This function is called on the load of sidebar buddylist panel. This adds a sidebarBuddyListObserver 
  1707.  * which get notified when the Buddy List is loaded.
  1708.  *
  1709.  * Author: Suresh
  1710.  */
  1711.  
  1712. function addSidebarBuddyListObserver() {
  1713.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1714.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1715.   if (observerService)
  1716.     observerService.addObserver(sidebarBuddyListObserver, "buddyListLoaded", false);
  1717. }
  1718.  
  1719. /*
  1720.  * Function: removeSidebarBuddyListObserver
  1721.  *
  1722.  * Arguments: None
  1723.  *
  1724.  * Return: None
  1725.  *
  1726.  * Description: This function is called on the Unload of sidebar buddylist panel. This removes the existing buddy list observer 
  1727.  * on the current sidebarpanel.
  1728.  *
  1729.  * Author: Suresh
  1730. */
  1731.  
  1732. function removeSidebarBuddyListObserver() {
  1733.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1734.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1735.   if (observerService)
  1736.     observerService.removeObserver(sidebarBuddyListObserver, "buddyListLoaded");
  1737. }
  1738.  
  1739. var sidebarBuddyListObserver = {
  1740.   observe: function(subject, message, data) {
  1741.     if (message == 'buddyListLoaded')  {
  1742.       SelectIndex(0);
  1743.       setThrobberState(false);
  1744.       //if (!isIcq()) {
  1745.         //openAIMToday();
  1746.       //}
  1747.     }
  1748.   }
  1749. }
  1750.  
  1751. function openAIMToday()
  1752. {
  1753.   var aimTodaypref = aimPrefsManager().GetBoolPref("aim.general.today", null, false);
  1754.   if (aimTodaypref) {
  1755.     var navigatorWindow;
  1756.     var possibleNavigator = top.document.getElementById("main-window");
  1757.     if (possibleNavigator && possibleNavigator.getAttribute("windowtype") == "navigator:browser")
  1758.       navigatorWindow = top;
  1759.  
  1760.     const WMEDIATOR_CONTRACTID     = "@mozilla.org/appshell/window-mediator;1";
  1761.     const nsIWindowMediator        = Components.interfaces.nsIWindowMediator;
  1762.     // if not, get the most recently used browser window
  1763.     if (!navigatorWindow) {
  1764.       var wm = Components.classes[WMEDIATOR_CONTRACTID].getService(nsIWindowMediator);
  1765.       navigatorWindow = wm.getMostRecentWindow("navigator:browser");
  1766.     }
  1767.  
  1768.     // if no browser window available open the mini browser
  1769.     if (!navigatorWindow)
  1770.       aimToday();
  1771.  
  1772.   }  
  1773.  
  1774. }
  1775.  
  1776.  
  1777. function setThrobberState(state)
  1778. {
  1779.   if ((IsApp) && (!IsSidebar)) {
  1780.     if (state)
  1781.       top.document.getElementById("navigator-throbber").setAttribute("busy", "true");
  1782.     else
  1783.       top.document.getElementById("navigator-throbber").setAttribute("busy", "false");
  1784.   }
  1785. }
  1786.  
  1787. function SwitchView(resource)
  1788. {
  1789.   if (!resource)
  1790.     return;
  1791.   var aimsession = aimSession();
  1792.   var aimPrefs = aimPrefsManager();
  1793.   if (resource == "ScreenNameWithStatus") {
  1794.     aimPrefs.SetIntPref("aim.session.buddyview", 0, null, false);
  1795.     aimsession.SetSessionBuddyListView(Components.interfaces.nsAimBuddyListViews.ScreenName);
  1796.   }
  1797.   else { 
  1798.     if (resource == "DisplayName") {
  1799.       aimPrefs.SetIntPref("aim.session.buddyview", 1, null, false);
  1800.       aimsession.SetSessionBuddyListView(Components.interfaces.nsAimBuddyListViews.DisplayName);
  1801.     }
  1802.   }
  1803.  
  1804.   var rdf = aimRDF();
  1805.   var res = rdf.GetResource("http://home.netscape.com/NC-rdf#" + resource);
  1806.   var aimbuddy = aimBuddyManager();
  1807.   aimbuddy.SwitchView(res);
  1808. }
  1809.  
  1810. function cmdDispName() {
  1811.   var ascreenName = getSelectedScreenName();
  1812.   if (!ascreenName) {
  1813.     aimErrorBox(aimString("msg.selBuddy"));
  1814.     return;
  1815.   }
  1816.   window.openDialog('chrome://aim/content/AimDisplayName.xul','_blank','chrome,titlebar,dialog=yes,centerscreen,modal=yes', ascreenName);
  1817. }
  1818.  
  1819.